package operator;
/**
 * @author Feri
 */
/**
 *  This class is the implementation of subtraction. <br />
 * See <A href="https://sites.google.com/site/sabloanedeproiectare/refactoring" > Design Patterns Lab </A>
 */
public class Minus extends Operator{
	/**
	 * Same as Calcul(double aux1, double aux2).
	 */
	public double calcul(double aux1, double aux2){
		return aux1 - aux2;
	}
	/**
	 * 
	 * @param aux1 First auxiliary variable.
	 * @param aux2 Second auxiliary variable.
	 * @return Returns the value of aux1-aux1.
	 */
	public double Calcul(double aux1, double aux2){
		return aux1 - aux2;
	}
	/**
	 * @return Returns the value of the derivation of the (left son)-(right son)
	 */
	public double calculDerivata(){
		if (fStang == null || fDrept == null)
			System.exit(1);
		return calcul(fStang.calculDerivata(), fDrept.calculDerivata());
	}
	/**
	 * @return Returns the derivation of the (left son)-(right son)
	 */
	public String derivare(){
		if (fStang == null || fDrept == null)
			System.exit(1);
		return concatTermeni(fStang.derivare(), fDrept.derivare());
	}
	/**
	 * @param aux1 Auxiliary variable
	 * @param aux2 Auxiliary variable
	 * @return Returns the concatenation of aux1 and aux2
	 * 
	 */
	public String concatTermeni(String aux1, String aux2){
		String aux;
		if (aux1.compareTo("0") == 0 || aux2.compareTo("0") == 0)
		aux = aux1;
		else if (aux1.compareTo("0") == 0) aux = aux2;
		else if (aux2.compareTo("0") == 0 ) aux = aux1;
		else
			aux = aux1 + "-" + aux2;
		return aux;
	}
	/**
	 * @param aux1 Auxiliary variable
	 * @param aux2 Auxiliary variable
	 * @return Returns the concatenation of aux1 and aux2
	 * 
	 */
	public static String concatTermens(String aux1, String aux2){
		String aux;
		if (aux1.compareTo("0") == 0 || aux2.compareTo("0") == 0)
		aux = aux1;
		else if (aux1.compareTo("0") == 0) aux = aux2;
		else if (aux2.compareTo("0") == 0 ) aux = aux1;
		else
			aux = aux1 + "-" + aux2;
		return aux;
	}
}
